import 'package:get/get.dart';

class PullDownMenuController extends GetxController {
  double? dropDownMenuTop;

  int menuIndex = 0;

  bool isShow = false;

  bool isRemoveMenu = false;

  bool isShowHideAnimation = false;

  bool isReloadMenu = false;

  Map<int, dynamic> chosenData = {};

  void show(int index) {
    isShow = true;
    menuIndex = index;
    update();
  }

  void hide({bool isShowHideAnimation = true}) {
    this.isShowHideAnimation = isShowHideAnimation;
    isShow = false;
    update();
  }

  void setNewChosenData(Map<int, dynamic> map) {
    chosenData = map;
    update();
  }

  void changeChosenData(dynamic data) {
    chosenData[menuIndex] = data;
  }

  void reload() {
    update();
  }

  /// 外部调用刷新菜单
  void reloadMenuList() {
    isReloadMenu = true;
    update();
  }

  /// 自定义menulist选中后需掉该方法把对应的数据传过来
  void setChooseItemData(dynamic data, {int? changeIndex}) {
    isRemoveMenu = true;
    if (changeIndex != null) {
      chosenData[changeIndex] = data;
    } else {
      changeChosenData(data);
    }
    hide();
  }

  /// 外部调用重置状态
  void resetPullDownState() {
    isRemoveMenu = true;
    hide();
  }
}
